{% extends "contest/base.html" %}
{% load full_time %}
{% block contest_page_title %}用户提问 - {% endblock %}
{% block contest_page_head %}
<script type="text/javascript" src="/static/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/static/library/jstorage.min.js"></script>
<script type="text/javascript" src="/static/library/sisyphus.min.js"></script>
<script type="text/javascript">
    $(function () {
        CKEDITOR.replace( 'content', { height:'25em' } );
        window.onunload = function () {
            sis.manuallyReleaseData();
        };

        var sis = $("#form_message").sisyphus({
            locationBased: true,
            timeout: 0,
            onSave: function () {
                $(window).bind('beforeunload',function(){
                    return "确定离开此页面吗？未保存的内容将会丢失！";
                });
            }
        });
        $("#form_message").submit(function (){
            for (var ins in CKEDITOR.instances) CKEDITOR.instances[ins].updateElement();
            $.GRestP({
               responseType: 'json',
                callback: function (flag, entity) {
                    if(flag){
                        $.AlertBox({
                            body: "发布成功",
                            color: "success",
                            title: "操作成功",
                            callback: function () {
                                $.ModalBox({}).hide();
                                $(window).unbind('beforeunload');
                                window.location.href='{% url 'contest_faq' contest.id %}';
                            }
                        }).show();
                    }else{
                        $.AlertBox({body: entity.msg, color: "danger", title: "操作失败"}).show();
                    }
                }
            }).submit_form(this);
            return false;
        });
    });

</script>
{% endblock %}
{% block contest_page_body %}
    <h3>{% if is_referee %}发布全站公告{% else %}向裁判提问{% endif %}</h3><hr />
    <form method="post" id="form_message" action="{% url 'contest_faq_save_new_msg' contest.id %}">
        <div class="input-group">
            <div class="input-group-addon">主题</div>
            <input type="text" class="form-control" name="subject">
        </div>
        <br>
        <textarea name="content" id="content"></textarea><br />
        <input type="submit" value="提交" class="btn btn-success"/>
    </form>
{% endblock %}